package org.sucri.floxs.ext.widget;

import org.sucri.floxs.ext.Function;
import org.sucri.floxs.ext.JsonConfig;
import org.sucri.floxs.ext.Ext_Util;
import org.sucri.floxs.html.CSS;
import net.sf.json.JSONObject;

/**
 * Created by IntelliJ IDEA.
 * User: Wen Yu
 * Date: Jul 19, 2007
 * Time: 10:20:27 PM
 * To change this template use File | Settings | File Templates.
 */
public class Column extends JsonConfig
{
  public Column() { super(); }
  public Column(String header) { super(); setHeader(header); }
  public Column(String header, int w) { super(); setHeader(header); setWidth(w); }

  private static final String HEADER     = "header";    // The header text to display in the Grid view.

  // Optional fields
  private static final String ALIGN      = "align";     // Set the CSS text-align property of the column. Defaults to undefined.
  private static final String DATA_INDEX = "dataIndex"; // The name of the field in the grid's Ext.data.Store's
                                                        // Ext.data.Record definition from which to draw the column's
                                                        // value. If not specified, the column's index is used as an
                                                        // index into the Record's data Array.
  private static final String HIDDEN     = "hidden";    // True to hide the column. Defaults to false.
  private static final String LOCKED     = "locked";    // True to lock the column in place while scrolling the Grid. Defaults to false.
  private static final String RESIZABLE  = "resizable"; // False to disable column resizing. Defaults to true.
  private static final String SORTABLE   = "sortable";  // True if sorting is to be allowed on this column. Defaults
                                                        // to true. Whether local/remote sorting is used is specified in remoteSort.
  private static final String WIDTH      = "width";     // The initial width in pixels of the column. Using this instead of Ext.grid
  private static final String RENDERER   = "renderer";  // A function used to generate HTML markup for a cell given
                                                        // the cell's data value. See setRenderer. If not specified,
                                                        // the default renderer uses the raw data value.

  public void setHeader(    String s) { mProperties.put(HEADER,     s); }
  public void setDataIndex( String s) { mProperties.put(DATA_INDEX, s); }
  public void setAlign(  CSS.Align s) { mProperties.put(ALIGN,      s.toString()); }
  public void isHidden(    boolean s) { mProperties.put(HIDDEN,     s); }
  public void isResizable( boolean s) { mProperties.put(RESIZABLE,  s); }
  public void isSortable(  boolean s) { mProperties.put(SORTABLE,   s); }
  public void isLocked(    boolean s) { mProperties.put(LOCKED,     s); }
  public void setWidth(        int s) { mProperties.put(WIDTH,      s); }
  public void setRenderer(Function s) { setRenderer(s.toString()); }
  public void setRenderer(String   s) { mProperties.put(RENDERER,   s.toString()); }
}
